// resizeScreen 函数：负责页面缩放适配
function resizeScreen() {
    const designWidth = 3840; // 设计稿宽
    const designHeight = 2160; // 设计稿高

    const scaleX = window.innerWidth / designWidth;
    const scaleY = window.innerHeight / designHeight;

    const content = document.querySelector('.content');
    // 宽高独立缩放，保证铺满全屏
    content.style.transform = `scale(${scaleX}, ${scaleY})`;
    content.style.transformOrigin = 'top left';
    content.style.position = 'absolute';
    content.style.left = '0';
    content.style.top = '0';
}

// 防抖函数，避免 resize 事件频繁调用
function debounce(func, wait) {
    let timeout;
    return function () {
        const context = this;
        const args = arguments;
        clearTimeout(timeout);
        timeout = setTimeout(() => func.apply(context, args), wait);
    };
}

// 更新星期显示
function updateWeek() {
    const now = new Date();
    const weekDays = [
        '星期日',
        '星期一',
        '星期二',
        '星期三',
        '星期四',
        '星期五',
        '星期六',
    ];
    document.getElementById('week').textContent = weekDays[now.getDay()];
}

// 更新时间和日期显示
function updateDateTime() {
    const now = new Date();

    // 更新时间
    const hours = now.getHours().toString().padStart(2, '0');
    const minutes = now.getMinutes().toString().padStart(2, '0');
    const seconds = now.getSeconds().toString().padStart(2, '0');
    document.getElementById('time').textContent = `${hours}:${minutes}:${seconds}`;

    // 更新日期
    const year = now.getFullYear();
    const month = (now.getMonth() + 1).toString().padStart(2, '0');
    const day = now.getDate().toString().padStart(2, '0');
    document.getElementById('year').textContent = `${year}-${month}-${day}`;
}

// 初始化页面事件和定时器
document.addEventListener('DOMContentLoaded', function () {
    resizeScreen();

    // 监听窗口大小变化，防抖处理
    const debouncedResize = debounce(resizeScreen, 100);
    window.addEventListener('resize', debouncedResize);

    // 初始化时间显示
    updateWeek();
    updateDateTime();

    // 每秒更新时间
    setInterval(() => {
        updateWeek();
        updateDateTime();
    }, 1000);
});
